package KogSys;

public class Dilation {
	public static int[][] dilation(int[][] bild, int n) {
		int k = (n - 1) / 2;
		int[][] bild2 = new int[k][k];
		for (int v = k; v < bild.length - k; v++) {
			for (int u = k; u < bild[0].length - k; u++) {
				if (bild[u][v] == 255) {
					for (int i = -k; i < k; i++) {
						for (int j = -k; j < k; j++) {
							bild2[u + j][v + i] = 255;
						}
					}
				}
			}
		}
		return bild2;
	}

	public static void printMatrix(int[][] m) {
		for (int i = 0; i < m.length; i++) {
			for (int j = 0; j < m[0].length; j++) {
				if (m[i][j] != 0) {
					System.out.print(m[i][j] + " ");
				} else {
					System.out.print(m[i][j] + "   ");
				}
			}
			System.out.println();
		}
	}

	public static void main(String[] args) {
		int[][] m = { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 255, 255, 255, 0, 0 }, { 0, 0, 255, 0, 255, 0, 0 },
				{ 0, 0, 255, 255, 255, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0 } };
		m = dilation(m,3);

		// int[][] m = { { 1, 2, 3, }, { 4, 5, 6, } };
		printMatrix(m);
	}
}
